<?php

	// namespace nz\co\gravitate\FTAPHPList;
	
	require_once("fta.201003310000/fta.php");	
	fta_registerModules(
		array(
			"FTAORM/FTAORM"
		)
	);

	// use \FTAORM;
		
	
	class FTAPHPListUserSignup extends \FTAORM {
		/*
		*  Posts  newsletter signup form to phplist
		*  Notes on customising the sign up form:-
		* - form enctype must be - enctype="multipart/form-data"
		* - email field must be named 'email'
		* - email confirm field must be named 'emailconfirm'
		* - attribute name syntax must be -> 'attribute[attribute_id in phplist_user_attribute table]'.. e.g. attribute name in phplist_user_attribute table has id '5'. so, in the form it should be like this:
		* <input type="text" name="attribute5" value="" />
		* and  ALSO, submit button must have name 'subscribe' - <input name="subscribe" type="submit" />
		*/
		
		// we can add stuff (functions) here as required :/
		static function phpListSignup($listId, $postData, $postURL){		
			if(is_null($listId) || !is_array($postData) || (is_array($postData) && count($postData) == 0) || is_null($postURL))
				return;
		
			// other data that phplist requires, we don't need to have these in the form as there are always chances of missing these out
			@$postData['process'] = 1;
			@$postData['VerificationCodeX'] = "";
			@$postData['list[' . $listId . ']'] = "signup";
			@$postData['listname[' . $listId . ']'] = "Test!";
			
			if(!isset($postData['emailconfirm'])){
				@$postData['emailconfirm'] = $postData['email'];
			}			
			// myPrintR($postData);

			// submit form using curl
			$curl_session = curl_init($postURL);	
			// set this to false, if you want to see the resulting page $postURL
			curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
			curl_setopt ($curl_session, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt ($curl_session, CURLOPT_POST, 1);
			curl_setopt ($curl_session, CURLOPT_POSTFIELDS, $postData);
			curl_exec ($curl_session);
			curl_close ($curl_session);
		}
	}

	
	
